package com.example.mall.web.controller;

import com.example.mall.domain.OperationLogs;
import com.example.mall.dto.OperationLogsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.OperationLogsQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IOperationLogsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/operationLogs")
public class OperationLogsController {

    @Autowired
    public IOperationLogsService operationLogsService;

    /**
     * 分页查询操作日志表信息
     * @param operationLogsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询操作日志表信息",notes = "分页查询操作日志表信息",httpMethod = "GET")
    public JSONResult queryPage(OperationLogsQuery operationLogsQuery){
        PageDTO<OperationLogsDto> operationLogsDtoPageDTO = operationLogsService.queryPage(operationLogsQuery);
        return JSONResult.success("查询成功",operationLogsDtoPageDTO);
    }

    /**
     * 根据id查询操作日志表信息
     * @param operationId
     * @return
     */
    @GetMapping("query/{operationId}")
    @ApiOperation(value = "根据id查询操作日志表信息",notes = "根据id查询操作日志表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("operationId")Long operationId){
        //1.根据id查询用户信息
        if (operationId == null){
            throw new GlobalCustomerException(ErrorEnumCode.OPERATIONID_NOT_ID);
        }
        OperationLogs operationLogs = operationLogsService.getById(operationId);
        return JSONResult.success("查询成功",operationLogs);
    }

    /**
     * 根据id查询操作日志表信息
     * @param operationId
     * @return
     */
    @GetMapping("queryOperationLogsById/{operationId}")
    @ApiOperation(value = "根据id查询操作日志表信息",notes = "根据id查询操作日志表信息",httpMethod = "GET")
    public JSONResult queryOperationLogsById(@PathVariable("operationId")Long operationId){
        //1.根据id查询用户信息
        if (operationId == null){
            throw new GlobalCustomerException(ErrorEnumCode.OPERATIONID_NOT_ID);
        }
        OperationLogs operationLogs = operationLogsService.queryOperationLogsById(operationId);
        return JSONResult.success("查询成功",operationLogs);
    }

    /**
     * 查询全部操作日志表信息
     * @param
     * @return
     */
    @GetMapping("queryOperationLogsList")
    @ApiOperation(value = "查询全部操作日志表信息",notes = "查询全部操作日志表信息",httpMethod = "GET")
    public JSONResult queryOperationLogsList(){
        List<OperationLogs> operationLogs = operationLogsService.queryOperationLogsList();
        return JSONResult.success("查询成功",operationLogs);
    }

    /**
     * 新增操作日志表
     * @param operationLogsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增操作日志表",notes = "新增操作日志表",httpMethod = "POST")
    public JSONResult insert(@RequestBody OperationLogsDto operationLogsDto){
        operationLogsService.insert(operationLogsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改操作日志表信息
     * @param operationLogsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改操作日志表信息",notes = "修改操作日志表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody OperationLogsDto operationLogsDto){
        operationLogsService.update(operationLogsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除操作日志表信息
     * @param operationId
     * @return
     */
    @PostMapping("delete/{operationId}")
    @ApiOperation(value = "删除操作日志表信息",notes = "删除操作日志表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("operationId") Long operationId) {
        operationLogsService.delete(operationId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除操作日志表信息
     * @param operationIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除操作日志表信息",notes = "批量删除操作日志表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> operationIds) {
        operationLogsService.deleteBatch(operationIds);
        return JSONResult.success("批量删除成功");
    }
}
